package net.zoneland.zrdp.web.controller.system;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import net.zoneland.zrdp.common.annotation.Log;
import net.zoneland.zrdp.common.core.controller.BaseController;
import net.zoneland.zrdp.common.core.domain.AjaxResult;
import net.zoneland.zrdp.common.core.page.TableDataInfo;
import net.zoneland.zrdp.common.enums.BusinessType;
import net.zoneland.zrdp.common.utils.poi.ExcelProcessor;
import net.zoneland.zrdp.system.domain.SysNoticeComment;
import net.zoneland.zrdp.system.service.ISysNoticeCommentService;

/**
 * 公告评论Controller
 *
 * @author zonevue
 */
@RestController
@RequestMapping("/system/comment")
public class SysNoticeCommentController extends BaseController {
    @Resource
    private ISysNoticeCommentService sysNoticeCommentService;

    /**
     * 查询公告评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(final SysNoticeComment sysNoticeComment) {
        startPage();
        final List<SysNoticeComment> list = sysNoticeCommentService.selectSysNoticeCommentList(sysNoticeComment);
        return getDataTable(list);
    }

    /**
     * 导出公告评论列表
     */
    @PreAuthorize("@ss.hasPermi('system:comment:export')")
    @Log(title = "公告评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(final HttpServletResponse response, final SysNoticeComment sysNoticeComment) {
        final List<SysNoticeComment> list = sysNoticeCommentService.selectSysNoticeCommentList(sysNoticeComment);
        final ExcelProcessor<SysNoticeComment> util = new ExcelProcessor<>(SysNoticeComment.class);
        util.exportExcel(response, list, "公告评论数据");
    }

    /**
     * 获取公告评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:comment:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") final Long id) {
        return success(sysNoticeCommentService.selectSysNoticeCommentById(id));
    }

    /**
     * 新增公告评论
     */
    @PreAuthorize("@ss.hasPermi('system:comment:add')")
    @Log(title = "公告评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody final SysNoticeComment sysNoticeComment) {
        return toAjax(sysNoticeCommentService.insertSysNoticeComment(sysNoticeComment));
    }

    /**
     * 修改公告评论
     */
    @PreAuthorize("@ss.hasPermi('system:comment:edit')")
    @Log(title = "公告评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody final SysNoticeComment sysNoticeComment) {
        return toAjax(sysNoticeCommentService.updateSysNoticeComment(sysNoticeComment));
    }

    /**
     * 删除公告评论
     */
    @PreAuthorize("@ss.hasPermi('system:comment:remove')")
    @Log(title = "公告评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable final Long[] ids) {
        return toAjax(sysNoticeCommentService.deleteSysNoticeCommentByIds(ids));
    }
}
